package com.example.system.controller;

import com.example.reception.entity.Order;
import com.example.system.model.ApiResponse;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * author: adnaan
 * create: 2023-11-16 19:52
 * Description:
 */
@RestController
@RequestMapping("/orderStatus")
public class OrderStatusController {

    @Resource
    private MongoTemplate mongoTemplate;

    @PutMapping("/saveStatus")
    public ApiResponse saveOrderStatus(@RequestBody Order order){
        Query query = new Query(Criteria.where("id").is(order.getId()));
        Update update=new Update();
        update.set("status",order.getStatus());
        return ApiResponse.success(mongoTemplate.updateMulti(query, update,Order.class));
    }
}
